package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author 星河一叶Ck
 * @date 2024/9/17
 */

// RestController里面的值是可以设置在Spring容器中该类的名字
@RestController("userShopController")
@RequestMapping("/user/shop")
@Slf4j
@Api(tags = "店铺相关接口")
public class ShopController {

    // 自动注入redis 用于redis 的使用
    @Autowired
    private RedisTemplate redisTemplate;

    // 设置常量
    public static final String KEY = "SHOP_STATUS";

    /**
     * 获取店铺状态
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("店铺设置为:{}",status == 1 ? "营业中" : "打洋中");
        return Result.success(status);
    }
}
